// Tags:
#include <algorithm>
#include <cctype>
#include <cstdio>

typedef long long ll;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 1e5 + 5, M = 3e5 + 5, lim = 1e7 + 5;
int n, m;
ll ans, f[M];

struct Obj {
  int w;
  ll p;

  inline bool operator<(const Obj &rhs) const { return p * rhs.w < rhs.p * w; }

} a[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("sell.in", "r", stdin);
  freopen("sell.out", "w", stdout);
#endif
#endif

  read(n), read(m);
  for (int i = 1; i <= n; ++i) { read(a[i].w), read(a[i].p); }
  std::sort(a + 1, a + n + 1);
  while (n && m >= a[n].w && (ll)n * m > lim) {
    m -= a[n].w;
    ans += a[n--].p;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = m; j >= a[i].w; --j) {
      f[j] = std::max(f[j], f[j - a[i].w] + a[i].p);
    }
  }
  printf("%lld", ans + f[m]);
  return 0;
}